package com.lancoo.ccas52.util;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.poi.ss.formula.functions.T;

import java.io.Serializable;


@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(description = "返回数据值")
public class ResponseObject<T> implements Serializable {


    @ApiModelProperty(value = "异常提示信息")
    private String message;

    @ApiModelProperty(value = "返回值编码；0表示成功，其他全部失败")
    private Integer code;

    @ApiModelProperty(value = "具体返回值信息")
    private T data;

    public static <T> ResponseObject<T> ofSuccess() {
        ResponseObject<T> result = new ResponseObject<T>();
        result.code = EnumResultCode.SUCCESS.getCode();
        result.message = EnumResultCode.SUCCESS.getResultMsg();
        return result;
    }

    public static <T> ResponseObject<T> ofSuccess(Integer code, String msg) {
        ResponseObject<T> result = new ResponseObject<T>();
        result.code = code;
        result.message = msg;
        return result;
    }

    public static <T> ResponseObject<T> ofSuccess(Integer code, String msg, T data) {
        ResponseObject<T> result = new ResponseObject<T>();
        result.code = code;
        result.message = msg;
        result.setData(data);
        return result;
    }

    public static <T> ResponseObject<T> ofSuccess(EnumResultCode resultCode) {
        ResponseObject<T> result = new ResponseObject<T>();
        result.code = resultCode.getCode();
        result.message = resultCode.getResultMsg();
        return result;
    }

    public static <T> ResponseObject<T> ofSuccess(T data) {
        ResponseObject<T> result = new ResponseObject<T>();
        result.code = EnumResultCode.SUCCESS.getCode();
        result.message = EnumResultCode.SUCCESS.getResultMsg();
        result.setData(data);
        return result;
    }

    public static <T> ResponseObject<T> ofFail(String msg) {
        ResponseObject<T> result = new ResponseObject<T>();
        result.code = EnumResultCode.FAIL.getCode();
        result.message = msg;
        return result;
    }

    public static <T> ResponseObject<T> ofFail(Integer code, String msg) {
        ResponseObject<T> result = new ResponseObject<T>();
        result.code = code;
        result.message = msg;
        return result;
    }

    public static <T> ResponseObject<T> ofFail(Integer code, String msg, T data) {
        ResponseObject<T> result = new ResponseObject<T>();
        result.code = code;
        result.message = msg;
        result.setData(data);
        return result;
    }

    public static <T> ResponseObject<T> ofFail(EnumResultCode resultEnum) {
        ResponseObject<T> result = new ResponseObject<T>();
        result.code = resultEnum.getCode();
        result.message = resultEnum.getResultMsg();
        return result;
    }

    public static <T> ResponseObject<T> ofFail(EnumResultCode resultEnum, T data) {
        ResponseObject<T> result = new ResponseObject<T>();
        result.code = resultEnum.getCode();
        result.message = resultEnum.getResultMsg();
        result.data = data;
        return result;
    }

}
